import { getInstance } from "/@/utils/request";

const state = {
  user: {},
  menu: [
    {
      url: "/",
      name: "酒店信息"
    },
    {
      url: "/room",
      name: "酒店房间",
      sub: [
        {
          url: "/all",
          name: "所有房间"
        },
        {
          url: "/type",
          name: "新增房间类型"
        },
        {
          url: "/add",
          name: "新增房间"
        }
      ]
    },
    {
      url: "/order",
      name: "酒店订单",
      sub: [
        {
          url: "/all",
          name: "所有订单"
        }
      ]
    }
  ]
}

const mutations = {
  setUser(state, user){
    state.user = user;
  }
}

const actions = {
  async setUser({commit}){
    let token = localStorage.getItem("token");
    let user = await getInstance(token).get("/user");
    commit("setUser", user.data);
  }
}

export default {
    namespaced: true,
    mutations,
    actions,
    state
  }